﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HAUtil;

namespace HA.ModFlow.Application
{


    /// <summary>
    /// 配置文件管理服务，提供应用程序配置文件的所有基础操作
    /// </summary>
    public class ConfigService
    {
        protected ConfigService()
        {
 
        }




        static ConfigService defaultService;

        public static ConfigService DefaultService
        {
            get {

                if (defaultService ==null)
                {
                    defaultService = new ConfigService();
                    
                }
                
                return ConfigService.defaultService; 
            
            }
           
        }


        ModflowSettingInfo _settingInfo;

        /// <summary>
        /// 程序配置信息
        /// </summary>
        public ModflowSettingInfo SettingInfo
        {
            get { return _settingInfo; }
            set { _settingInfo = value; }
        }

        string _fileName = "hamod.set";

        /// <summary>
        /// 从硬盘加载配置文件
        /// </summary>
        public void LoadConfig()
        {
            string filePath=  ApplicationService.DefalutService.GetApplicationPath(ApplicationPath.APPPATH)+this._fileName;

            bool b=false;

            if (System.IO.File.Exists(filePath))
            {
                this._settingInfo = FileOperations.OpenFromBinary(filePath, ref b) as ModflowSettingInfo;
                if (this._settingInfo==null)
                {
                    this._settingInfo = new ModflowSettingInfo();
                    
                }



            }
            else
            {
                this._settingInfo = new ModflowSettingInfo();

            }

 
        }


        /// <summary>
        /// 将配置文件保存会硬盘
        /// </summary>
        public void SaveConfig()
        {

            string filePath = ApplicationService.DefalutService.GetApplicationPath(ApplicationPath.APPPATH) + this._fileName;

            FileOperations.SaveToBinary(filePath,this._settingInfo);

 
        }

    }
}
